<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>
    <script src="./city.js"></script>
</head>

<body>
    <!-- 省级联动 -->
    <select name="" id="province" class="form-control">
        <!-- <option value="">请选择省：</option> -->
    </select>
    <!-- 市级联动 -->
    <select name="" id="city" class="form-control">
        <option value="">请选择市：</option>
    </select>
    <!-- 县级联动 -->
    <select name="" id="county" class="form-control">
        <option value="">请选择县：</option>
    </select>
</body>
<script>
    $(function () {
        var str = '<option value="">请选择省：</option>'
        for (let i in citys) {
            str += `<option value="${i}">${citys[i].name}</option>`
        }
        $('#province').html(str)
    })
        $('#province').change(function () {
            let index = $(this).val()
            let cityAll = citys[index].city
            let cityStr = '<option value="">请选择市：</option>'
            for (let i in cityAll) {
                cityStr += `<option value="${index}-${i}">${cityAll[i].name}</option>`
            }
            $('#city').html(cityStr)
        })
        $('#city').change(function(){
            let index = $(this).val()
            let indexAll = index.split('-')
            let area = citys[indexAll[0]].city[indexAll[1]].area
            let countyStr = '<option value="">请选择县：</option>'
            for (let i in area) {
                countyStr += `<option value="${index}-${i}">${area[i]}</option>`
            }
            $('#county').html(countyStr)
        })
  
</script>

</html>